package principle.factory.order;

import principle.factory.factoryClass.simpleFactory;
import principle.factory.simple.pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * @author malguy-wang sir
 * @create ${year}-${month}-${day}-${time}
 */
public abstract class orderPizza {
    public abstract pizza createPizza(String o);
    private pizza pizza = null;

    public orderPizza() {
        String orderType = "";
        do {
            orderType = getType();
            pizza = createPizza(orderType);//抽象方法，由子类工厂实现
            if (pizza != null) {
                pizza.prepare(orderType);
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("订购失败");
            }
        } while (true);
    }

    //获取订单内容
    public String getType() {
        try {
            BufferedReader type = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("输入要订购的类型");
            String str = type.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
